<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form class="verify-form" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="图片id" prop="imageId">
      <el-input v-model="dataForm.imageId" placeholder="图片id"></el-input>
    </el-form-item>
    <el-form-item label="粉丝姓名" prop="fansNameShow">
      <el-radio-group v-model="dataForm.fansNameShow">
        <el-radio :label="1">显示</el-radio>
        <el-radio :label="0">不显示</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="字体颜色" prop="fontColor">
      <el-input v-model="dataForm.fontColor" placeholder="字体颜色"></el-input>
    </el-form-item>
    <el-form-item label="字体大小" prop="fontSize">
      <el-input v-model="dataForm.fontSize" placeholder="字体大小"></el-input>
    </el-form-item>
    <el-form-item label="字体x轴坐标" prop="fontX">
      <el-input v-model="dataForm.fontX" placeholder="字体x轴坐标"></el-input>
    </el-form-item>
    <el-form-item label="字体y轴坐标" prop="fontY">
      <el-input v-model="dataForm.fontY" placeholder="字体y轴坐标"></el-input>
    </el-form-item>
    <el-form-item label="二维码" prop="qrCodeShow">
      <el-radio-group v-model="dataForm.qrCodeShow">
        <el-radio :label="1">显示</el-radio>
        <el-radio :label="0">不显示</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="二维码款宽度" prop="qrCodeWidth">
      <el-input v-model="dataForm.qrCodeWidth" placeholder="二维码款宽度"></el-input>
    </el-form-item>
    <el-form-item label="二维码x轴坐标" prop="qrCodeX">
      <el-input v-model="dataForm.qrCodeX" placeholder="二维码x轴坐标"></el-input>
    </el-form-item>
    <el-form-item label="二维码y轴坐标" prop="qrCodeY">
      <el-input v-model="dataForm.qrCodeY" placeholder="二维码y轴坐标"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getWxPromotePosterObj, addWxPromotePosterObj, putWxPromotePosterObj} from '@/api/mp/wxpromoteposter'

    export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          imageId: '',
          fansNameShow: 0,
          fontColor: '',
          fontSize: '',
          fontX: '',
          fontY: '',
          qrCodeShow: 0,
          qrCodeWidth: '',
          qrCodeX: '',
          qrCodeY: '',
          createTime: '',
          createUser: '',
          updateTime: '',
          updateUser: '',
          delFlag: ''
        },
        dataRule: {
          imageId: [
            { required: true, message: '图片id不能为空', trigger: 'blur' }
          ],
          fansNameShow: [
            { required: true, message: '粉丝姓名是否展示(1-是,0-否)不能为空', trigger: 'blur' }
          ],
          fontColor: [
            { required: true, message: '字体颜色不能为空', trigger: 'blur' }
          ],
          fontSize: [
            { required: true, message: '字体大小不能为空', trigger: 'blur' }
          ],
          fontX: [
            { required: true, message: '字体x轴坐标不能为空', trigger: 'blur' }
          ],
          fontY: [
            { required: true, message: '字体y轴坐标不能为空', trigger: 'blur' }
          ],
          qrCodeShow: [
            { required: true, message: '二维码是否展示(1-是,0-否)不能为空', trigger: 'blur' }
          ],
          qrCodeWidth: [
            { required: true, message: '二维码款宽度不能为空', trigger: 'blur' }
          ],
          qrCodeX: [
            { required: true, message: '二维码x轴坐标不能为空', trigger: 'blur' }
          ],
          qrCodeY: [
            { required: true, message: '二维码y轴坐标不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          createUser: [
            { required: true, message: '创建人不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          updateUser: [
            { required: true, message: '修改人不能为空', trigger: 'blur' }
          ],
          delFlag: [
            { required: true, message: '删除标识不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getWxPromotePosterObj(this.dataForm.id).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
                putWxPromotePosterObj(this.dataForm).then(data => {
                    this.$message.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                });
            } else {
                addWxPromotePosterObj(this.dataForm).then(data => {
                    this.$message.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                })
            }
          }
        })
      }
    }
  }
</script>
